﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace shujubangding
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public ListCollectionView MyCollectionView;
        public Order O;
        
        public MainWindow()
        {
            InitializeComponent();
        }
        public bool Contains (object de)
        {
            var order = de as Order;
            return (order?.Filled == "No");

        }
        public void StartHere(object sender,DependencyPropertyChangedEventArgs args)
        {
            MyCollectionView = (ListCollectionView)
                CollectionViewSource.GetDefaultView(rootElement.DataContext);
        }
        private void OnClick(object sender,RoutedEventArgs args)
        {
            var botton = sender as Button;
            MyCollectionView.SortDescriptions.Clear();
            switch (Button.Name)
            {
                case "orderButton":
                    MyCollectionView.SortDescriptions.Add(new SortDescription("OrderItem", ListSortDirection.Ascending));
                    break;
                case "customerButton":
                    MyCollectionView.SortDescriptions.Add(new SortDescription("Customer", ListSortDirection.Ascending));
                    break;
                case "nameButton":
                    MyCollectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                    break;
                case "idButton";
                    MyCollectionView.SortDescriptions.Add(new SortDescription("id", ListSortDirection.Ascending));
                    break;
                case "filledButton":
                    MyCollectionView.SortDescriptions.Add(new SortDescription("filled", ListSortDirection.Ascending));
                    break;
            }
;
        }
        private void OnBrowse(object sender RoutedEventArgs args)
        {
            var b = sender as Button;
            switch(b.Name)
                
                {
                case "Pervious":
                    if (MyCollectionView.MoveCurrentToPrevious())
                    {
                        feedbackText.Text = "";
                        O = MyCollectionView.CurrentItem as Order;
                    }
                    else
                    {
                        MyCollectionView.MoveCurrentToFirst();
                        feedbackText.Text = "At first record";
                    }
                    break;
                case "Next":
                    if(MyCollectionView.MoveCurrentToNext())
                    {
                        feedbackText.Text = "AT first record";
                    }
            }
        }
    }
}
